#include"SudokuCandidates.h"

SudokuCandidates::SudokuCandidates()
{
}

SudokuCandidates::SudokuCandidates(int size, bool value)
{
    mCandidates.fill(value, size);
    // TODO Empty or maybe diffetent default value?
    mEliminateTypeVector.fill(Empty, size);
}

SudokuCandidates::SudokuCandidates(const SudokuCandidates &other)
{
    if(this == &other)
        return;
    this->mCandidates = other.mCandidates;
    this->mEliminateTypeVector = other.mEliminateTypeVector;
}

SudokuCandidates& SudokuCandidates::operator=(const SudokuCandidates &other)
{
    if(this != &other)
    {
        this->mCandidates = other.mCandidates;
        this->mEliminateTypeVector = other.mEliminateTypeVector;
    }

    return *this;
}

SudokuCandidates::~SudokuCandidates()
{
}

void SudokuCandidates::resetEliminated()
{
    for(int i=0; i<mEliminateTypeVector.size(); ++i)
    {
        if(mEliminateTypeVector[i] == Elimination)
        {
            mEliminateTypeVector[i] = Empty;
            mCandidates.setBit(i, true);
        }
    }
}

int SudokuCandidates::getFirstPossibleIndex() const
{
    Q_ASSERT(mCandidates.count(true) > 0);
    int firstPossibleInd = 0;
    while(!mCandidates.testBit(firstPossibleInd))
        ++firstPossibleInd;
    return firstPossibleInd;
}

QList<int> SudokuCandidates::getCandidateList() const
{
    QList<int> candidateList;
    for(int i=0;i<mCandidates.size();++i)
        if(mCandidates.testBit(i))
            candidateList.append(i);//TODO +1 ??
    return candidateList;
}
